<?php
namespace catchAdmin\externalGoods\model;

use catchAdmin\basics\model\Official;
use catchAdmin\externalGoods\model\search\NewsSearch;
use catcher\base\CatchModel;
use think\Exception;
use think\facade\Db;

class TenantPricePrecent extends CatchModel
{

    protected $name = 'db_tenant_price_precent';
    protected $field = [
        'id',
        'tenant_id',
        'trade_type_id',
        'cost_percent',
        'price_percent',
        'discount_percent'
    ];

    public static function getPercentByTid($tenant_id,$trade_type_id,$tenant_type = 'cross'){
        $default = [
            'cost_percent'=>1.1,//成本价 仓库看到的价格，巧易云显示的成本价
            'price_percent'=>1.2650,
        ];

        $filed = 'tenant_id';
        if($tenant_type == 'qekj'){
            $filed = 'qekj_tenant_id';
        }

        $result = self::where([$filed=>$tenant_id,'trade_type_id'=>$trade_type_id])->find();

        if($result){
            $default['cost_percent'] = $result['cost_percent'];
            $default['price_percent'] = bcmul($result['price_percent'],$result['discount_percent'],4);
        }

        return $default;
    }
}
